package com.bindatax.event.impl.statistics.dblog.model;

import com.bindatax.core.custom.StatusCode;
import com.bindatax.core.statistics.ExecuteStatistics;
import com.bindatax.core.util.StringUtils;

import java.sql.Timestamp;

public class RunTimeLog {

    // 本次执行的数据行政区划代码
    private String xzqhdm;
    // 本次执行的数据行政区划名称
    private String xzqhmc;
    // 本次执行的源Schema
    private String schema;
    // 本次执行的目标表名
    private String tableName;
    // 原来的增量时间
    private Timestamp zlOldTime;
    // 最新的增量时间
    private Timestamp zlNewTime;
    private Integer input = 0;
    private Integer output = 0;
    private Integer update = 0;
    private Integer reject = 0;

    // 本次任务执行状态代码
    private Integer exeStatusCode;
    // 本次任务执行状态描述
    private String exeStatusDesc;
    // 本次任务开始时间
    private Timestamp startTime;
    // 本次任务结束时间
    private Timestamp endTime;
    // SQL模板的GUID
    private String sqlGuid;

    // 任务执行错误-简要概述
    private String exeFailSummary = "-";
    // 任务执行错误-详情
    private String exeFailDatail = "-";
    // 组
    private String groupBy;
    // 描述
    private String remarks;

    public RunTimeLog(StatusCode statusCode){
        this.exeStatusCode = statusCode.getCode();
        this.exeStatusDesc = statusCode.getDesc();
    }

    public RunTimeLog(){}

    public void setStatusCode(StatusCode statusCode){
        this.exeStatusCode = statusCode.getCode();
        this.exeStatusDesc = statusCode.getDesc();
    }

    public Timestamp getStartTime() {
        return startTime;
    }

    public void setStartTime(Timestamp startTime) {
        this.startTime = startTime;
    }

    public Timestamp getEndTime() {
        return endTime;
    }

    public void setEndTime(Timestamp endTime) {
        this.endTime = endTime;
    }

    public void setExeFailSummary(String exeFailSummary) {
        this.exeFailSummary = exeFailSummary;
    }

    public String getXzqhdm() {
        return xzqhdm;
    }

    public void setXzqhdm(String xzqhdm) {
        this.xzqhdm = xzqhdm;
    }

    public String getXzqhmc() {
        return xzqhmc;
    }

    public void setXzqhmc(String xzqhmc) {
        this.xzqhmc = xzqhmc;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Timestamp getZlOldTime() {
        return zlOldTime;
    }

    public void setZlOldTime(Timestamp zlOldTime) {
        this.zlOldTime = zlOldTime;
    }

    public Timestamp getZlNewTime() {
        return zlNewTime;
    }

    public void setZlNewTime(Timestamp zlNewTime) {
        this.zlNewTime = zlNewTime;
    }

    public Integer getExeStatusCode() {
        return exeStatusCode;
    }

    public void setExeStatusCode(Integer exeStatusCode) {
        this.exeStatusCode = exeStatusCode;
    }

    public String getExeStatusDesc() {
        return exeStatusDesc;
    }

    public void setExeStatusDesc(String exeStatusDesc) {
        this.exeStatusDesc = exeStatusDesc;
    }

    public String getSqlGuid() {
        return sqlGuid;
    }

    public void setSqlGuid(String sqlGuid) {
        this.sqlGuid = sqlGuid;
    }

    public String getExeFailSummary() {
        return exeFailSummary;
    }

    public void setErrorInfo(String errorTips,Exception ex){
        this.exeFailSummary = errorTips;
        if (ex != null){
            this.exeFailSummary += ": " + ex.getMessage();
            this.exeFailDatail = StringUtils.getExceptionInfo(ex);
        }
    }


    public String getExeFailDatail() {
        return exeFailDatail;
    }

    public void setExeFailDatail(String exeFailDatail) {
        this.exeFailDatail = exeFailDatail;
    }

    public Integer getInput() {
        return input;
    }

    public void setInput(Integer input) {
        this.input = input;
    }

    public Integer getOutput() {
        return output;
    }

    public void setOutput(Integer output) {
        this.output = output;
    }

    public Integer getUpdate() {
        return update;
    }

    public void setUpdate(Integer update) {
        this.update = update;
    }

    public Integer getReject() {
        return reject;
    }

    public void setReject(Integer reject) {
        this.reject = reject;
    }


    public String getGroupBy() {
        return groupBy;
    }

    public void setGroupBy(String groupBy) {
        this.groupBy = groupBy;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public void readStatisticsData(ExecuteStatistics statistics){
        this.input = statistics.getInput();
        this.output = statistics.getOutput();
        this.update = statistics.getUpdate();
        this.reject = statistics.getReject();
    }

    @Override
    public String toString() {
        return "RunTimeLog{" +
                "xzqhdm='" + xzqhdm + '\'' +
                ", xzqhmc='" + xzqhmc + '\'' +
                ", schema='" + schema + '\'' +
                ", tableName='" + tableName + '\'' +
                ", zlOldTime=" + zlOldTime +
                ", zlNewTime=" + zlNewTime +
                ", input=" + input +
                ", output=" + output +
                ", update=" + update +
                ", reject=" + reject +
                ", exeStatusCode=" + exeStatusCode +
                ", exeStatusDesc='" + exeStatusDesc + '\'' +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", sqlGuid='" + sqlGuid + '\'' +
                ", exeFailSummary='" + exeFailSummary + '\'' +
                ", exeFailDatail='" + exeFailDatail + '\'' +
                ", groupBy='" + groupBy + '\'' +
                ", remarks='" + remarks + '\'' +
                '}';
    }
}
